from models import RequirementClassification  # 添加这行导入
from datetime import datetime

def generate_req_id(node_code, type_suffix, request_time):
    """生成需求ID: REQ-{层级编码}-{类型后缀}-{年月日}-{流水号}"""
    date_str = request_time.strftime('%Y%m%d')
    
    # 查询当天的需求数量
    count = RequirementClassification.query.filter(
        RequirementClassification.req_id.like(f'REQ-{node_code}-{type_suffix}-{date_str}-%')
    ).count()
    
    seq_number = count + 1
    return f"REQ-{node_code}-{type_suffix}-{date_str}-{seq_number:03d}"

def calculate_priority(business_value, urgency, complexity):
    """计算综合优先级"""
    return max(1, min(10, (business_value * 5 + urgency * 3 - complexity * 2) // 3))

def get_full_path(node):
    """递归获取完整层级路径"""
    path = []
    current = node
    while current:
        path.insert(0, current.name)
        current = current.parent
    return ' > '.join(path)